﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DevExpress.Web.ASPxEditors;
using DevExpress.Web.Mvc;
using Dogshow.Model;
using Dogshow.Web.Services;
using DogshowRepository;
using Ninject;
using Dogshow.Web.Utils;

namespace Dogshow.Web.Controllers
{
    public class KinoloziController : Controller
    {
        private IRepoServices m_RepoService;

        public KinoloziController(IRepoServices mRepoService)
        {
            m_RepoService = mRepoService;
        }

        public static object FiltrirajKinologePoDeluImena(ListEditItemsRequestedByFilterConditionEventArgs args)
        {
            var repository = ((IKernel)Bootstrap.Bootstrapper.Container).Get<IKinoloziRepository>();
            var kinolozi = repository.FiltrirajPoImenu(args.Filter, args.BeginIndex, args.EndIndex - args.BeginIndex + 1);
            return kinolozi;
        }

        public static object FiltrirajKinologaPoId(ListEditItemRequestedByValueEventArgs args)
        {
            if (args.Value == null) return null;
            var repository = ((IKernel)Bootstrap.Bootstrapper.Container).Get<IKinoloziRepository>();
            var id = Convert.ToInt32(args.Value);
            return repository.VratiPoId(id);
        }

        public static IEnumerable<Kinolog> VratiKinologaPoId(int? id)
        {
            if (id == null) return Enumerable.Empty<Kinolog>();
            var repository = ((IKernel)Bootstrap.Bootstrapper.Container).Get<IKinoloziRepository>();
            return new[] { repository.VratiPoId(id.Value) ?? new Kinolog() };
        }
    }
}
